package models

import (
	"fresh-e-commerce/global"
	"gorm.io/gorm"
)

type Product struct {
	gorm.Model
	ProductTitle string  `gorm:"type:varchar(30);comment:'商品标题'"`
	ProductPrice float64 `gorm:"type:decimal(10,2);comment:'商品价格'"`
	ProductNum   int64   `gorm:"type:int(10);comment:'商品库存'"`
}

func (*Product) TableName() string {
	return "product"
}

func (p *Product) GetProductIdInfo(pid int64) error {
	if err := global.DB.Debug().Where("id=?", pid).Limit(1).Find(&p).Error; err != nil {
		return err
	}
	return nil
}

// 商品属性
type Attributes struct {
	gorm.Model
	ProductId             int64  `gorm:"type:int(10);comment:'商品id'"`
	ProductClassification string `gorm:"type:varchar(30);comment:'商品分类'"`
}

func (*Attributes) TableName() string {
	return "attributes"
}
